// pages/yoshop/article/channel.js
let _this;
let common = require('../../utils/common.js');
let Bmob = require('../../utils/bmob.js');
let App = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cIndex: 0,
    courses: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    _this = this;
    Bmob.initialize("8bbd2fa87eece23337234b59c300fb2e", "0422786c4a1502011b37da0d9f437770")
    _this.setData({cIndex: options.id})

    wx.setNavigationBarTitle({
      title: '课程',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    _this.getCourses()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 获取分类所属课程
   */
  getCourses: function() {
    let _url = 'classes/Article?where={"ChannelId":'+_this.data.cIndex+'}'

    App._get(_url, {}, function(res){
      console.log(res)
      _this.setData({courses: res.results})
    })
  }
})